//
//  HMStatusRetweetView.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/2/2.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit
import SnapKit
class HMStatusRetweetView: UIView {
    
    
    var pictureConstraints: Constraint?
    var statusViewModel: HMStatusViewModel?{
        didSet{
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            pictureConstraints?.uninstall()
            print(statusViewModel?.status?.retweeted_status?.pic_urls)
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0 {
                pictureView.hidden = false
                pictureView.pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls
                snp_makeConstraints(closure: { (make) -> Void in
                     self.pictureConstraints = make.bottom.equalTo(pictureView).offset(HMStatusCellMargin).constraint
                })
                
            }else {
                
                pictureView.hidden =  true
                snp_makeConstraints(closure: { (make) -> Void in
                    self.pictureConstraints = make.bottom.equalTo(contentLabel).offset(HMStatusCellMargin).constraint
                })
                
            }
           
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(HMStatusCellMargin)
            make.top.equalTo(self).offset(HMStatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(HMStatusCellMargin)
            
        }
        
        self.snp_makeConstraints { (make) -> Void in
            self.pictureConstraints = make.bottom.equalTo(pictureView).offset(HMStatusCellMargin).constraint
        }
    }
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15, maxWidth: SCREENW - HMStatusCellMargin * 2)
    
    private lazy var pictureView: HMStatusPictureView = {
       let pic = HMStatusPictureView()
        pic.backgroundColor = self.backgroundColor
        return pic
    }()
}
